<template>
  <div class="logoSearch">
    <div class="logo">
      <img src="../assets/imgs/mi-logo.png" alt="" />
    </div>
    <div class="fenlei">
      <ul>
        <li v-for="(item,index) in classList" 
        :key="index" 
        :class="{'lightHigh':index==currentindex,'active':currentindex!=-1}" 
        @mouseenter="mouseenter(index)"
        @mouseleave="mouseleave"
        >
        {{ item }}
        </li>
      </ul>
      <div class="glist" ref="glist">
        <ul style="display: flex;justify-content: space-around; align-items: center;">
            <li v-if="List.length!=0" v-for="(item,index) in List" :key="index" style="text-align: center;">
                <img :src="item.mainImage" width="230px">
                <span>{{ item.name }}</span>
                <span>{{ item.price }}</span>
            </li>
            <li v-if="List.length==0" style="margin-top: 30px;">
                暂无商品
            </li>
        </ul>
      </div>
    </div>
    <div class="search">
      <input type="text" />
      <span class="searchImg"></span>
    </div>
  </div>
</template>

<script>
export default {
  name: "logoSearch",
  data() {
    return {
        List:[],
        phoneList:[],
        currentindex:-1,
      classList: ['电视',"小米手机", "RedMi红米", "笔记本", "路由器", "家电"],
    };
  },
  methods:{
    mouseenter(index){
        console.log(index);
        this.currentindex = index;
        this.$refs.glist.style.height='220px'
        switch(index){
            case 1:
                this.List = this.phoneList 
                break;

            default:
                break;
        }
    },
    mouseleave(){
        this.currentindex = -1
        this.$refs.glist.style.height='0px';
        this.List = []
    }
  },
  mounted(){
    this.$axios.get('../../json/nav.json').then(res=>{
      console.log(res.data.data);
      this.phoneList = res.data.data.list
    })
  }
};
</script>
<style lang='less'>
.logoSearch {
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  .logo {
    margin-left: 30px;
    width: 50px;
    height: 50px;
    line-height: 50px;
    background-color: #ff6600;
  }
  .fenlei {
    min-width: 430px;
    .lightHigh{
        color: #ff6600;
    }
    ul {
      list-style: none;
      li {
        cursor: pointer;
        font-size: 16px;
        font-weight: bold;
        float: left;
        margin-left: 20px;
      }
    }
    .glist {
      position: absolute;
      z-index: 999;
      left: 0;
      top: 65px;
      overflow: hidden;
      height: 0px;
      width: 100%;
      background-color: #fff;
      transition: all 0.4s;
    }
  }
  .search {
    height: 42px;
    display: flex;
    margin-right: 60px;
    input {
      outline: none;
      border: 1px solid #ccc;
      min-width: 200px;
      height: 100%;
    }
    .searchImg {
      display: block;
      cursor: pointer;
      height: 100%;
      width: 44px;
      border: 1px solid #ccc;
      border-left: none;
      background: url(../assets/imgs/icon-search.png) no-repeat;
      background-size: 22px 22px;
      background-position: center;
    }
  }
}
</style>